package com.diaohaiwen.common.log;

import com.diaohaiwen.common.obj.log.DbLog;
import com.diaohaiwen.common.obj.log.LogbackLog;
import com.diaohaiwen.common.obj.log.RequestLog;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;

/**
 * @author 刁海文
 * @since 2024/1/14 18:21
 */
@EnableOperatorLog
@Configuration(proxyBeanMethods = false)
public class LogService {

    @Resource
    LogProperties logProperties;

    @Resource
    BaseLogSend logSend;

    /**
     * http 请求日志
     */
    public void executeHTTP(RequestLog log) {
        if (logProperties.isHttp()) {
            logSend.executeHTTP(log);
        }
    }

    /**
     * SQL日志配置
     */
    public void executeDB(DbLog log) {
        if (logProperties.isDb()) {
            logSend.executeDB(log);
        }

    }

    /**
     * 过滤的logger name 支持使用正则
     */
    public void executeLogback(LogbackLog log) {
        if (logProperties.isLogback()) {
            logSend.executeLogback(log);
        }
    }

}
